package instantHelper.Raceway;

import java.io.File;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.preference.PreferenceManager;
import android.provider.Settings.Secure;
import android.telephony.TelephonyManager;

public class SettingsUtil {

	// GENERAL
	public static String getProfileName(Context ctxt) {
		return getPreferenceValue("generalprofile", ctxt).toString();
	}

	public static boolean getDeleteDataControl(Context ctxt) {
		SharedPreferences prefs = getSharedPreferences(ctxt);
		Boolean storedPreference = prefs.getBoolean("deleteDataAfterSend",
				true);
		return storedPreference;
	}

	// VIDEO
	public static String getVideoFrameRate(Context ctxt) {
		return getPreferenceValue("framerate", ctxt).toString();
	}

	public static String getVideoMaximumDuration(Context ctxt) {
		return getPreferenceValue("maximumduration", ctxt).toString();
	}

	public static String getVideoQuality(Context ctxt) {
		return getPreferenceValue("videoquality", ctxt).toString();
	}

	// AUDIO
	public static String getAudioMaximumDuration(Context ctxt) {
		return getPreferenceValue("audiomaxduration", ctxt).toString();
	}

	public static String getAudioChannel(Context ctxt) {
		return getPreferenceValue("audiochannel", ctxt).toString();
	}

	public static String getAudioSamplingRate(Context ctxt) {
		return getPreferenceValue("audiosamplingrate", ctxt).toString();
	}

	public static String getAudioEncodingBitRate(Context ctxt) {
		return getPreferenceValue("audioencodingbitrate", ctxt).toString();
	}

	// PICTURE
	public static String getPictureQuality(Context ctxt) {
		return getPreferenceValue("picturequality", ctxt).toString();
	}

	// GENERIC
	public static Object getPreferenceValue(String key, Context ctxt) {
		SharedPreferences prefs = getSharedPreferences(ctxt);
		Object storedPreference = prefs.getString(key, null);
		return storedPreference;
	}

	public static SharedPreferences getSharedPreferences(Context ctxt) {
		return PreferenceManager.getDefaultSharedPreferences(ctxt);
	}

	public static String getIMEIAddress(Context cntx) {
		TelephonyManager telephonyManager = (TelephonyManager) cntx
				.getSystemService(Context.TELEPHONY_SERVICE);
		return telephonyManager.getDeviceId();
	}

	public static String getAndroidID(Context cntx) {
		return Secure.getString(cntx.getContentResolver(), Secure.ANDROID_ID);
	}

	public void showOptions(Context cntx) {
		PackageManager pm = cntx.getPackageManager();

		// check the system requirements
		boolean hasCamera = pm
				.hasSystemFeature(InstantHelperConstant.FEATURE_CAMERA);
		boolean hasGPS = pm
				.hasSystemFeature(InstantHelperConstant.FEATURE_LOCATION_GPS);
		boolean hasMicrophone = pm
				.hasSystemFeature(InstantHelperConstant.FEATURE_MICROPHONE);

	}

	public static void deleteFile(String filePath) {
		File file = new File(filePath);
		if (file.exists()) {
			file.delete();
		}
	}

}
